package com.qingke.easyjava.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;

public class LifecycleBean implements BeanPostProcessor,BeanFactoryAware,InitializingBean,DisposableBean{
	
	public void init(){
		System.out.println("calling LifecycleBean.init()");
	}

	public void destroy() throws Exception {
		System.out.println("calling LifecycleBean.destory()");
	}
	public void close(){
		System.out.println("calling LifecycleBean.close()");
	}

	public void afterPropertiesSet() throws Exception {
        System.out.println("calling LifecycleBean.afterPropertiesSet()");  		
	}

	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        ((DefaultListableBeanFactory)beanFactory).addBeanPostProcessor(this);
        System.out.println("calling LifecycleBean.setBeanFactory()");
	}
    public void setBeanName(String name){
    	System.out.println("calling LifecycleBean.setBeanName(),name="+name);
    }
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		System.out.println("calling LifecycleBean.postProcessAfterInitialization(),beanName="+beanName);
		return bean;
	}

	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		System.out.println("calling LifecycleBean.postProcessBeforeInitialization(),beanName="+beanName);
		return bean;
	}
	

}
